package com.spark.mooc.ch2_scala.part02_objectOrientedProgramming

/**
 * @description:
 * @time: 2020/11/24 16:52
 * @author: lhy
 */
abstract class ChineseCar(val name:String){
    val carBrand:String     //字段没有初始值，就是一个抽象字段
    def info()              // 抽象方法
    def greeting(): Unit ={
        println("welcome to my car!")
    }
}
// 扩展类实例
class BMWCar extends ChineseCar("宝马"){
    override val carBrand: String = "BMW"
    override def info(): Unit = printf("This is a %s car.It is expensive.\n",carBrand)
    override def greeting(): Unit = println("welcome to my BMW car!")
}
class BYDCar extends ChineseCar("比亚迪"){
    override val carBrand: String = "BYD"
    override def info(): Unit = printf("This is a %s car.It is expensive.\n",carBrand)
    override def greeting(): Unit = println("welcome to my BYD car!")
}
object TestExtends {
    def main(args: Array[String]): Unit = {
        val bmw = new BMWCar
        val byd = new BYDCar
        bmw.greeting()
        bmw.info()
        byd.greeting()
        byd.info()
    }
}
